package kjh820909.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import kjh820909.utils.OracleJDBC;

public class ZipcodeDAO {

	private static final String zipcodeSQL =
			"select * from ZIPCODE WHERE dong like ? ";
	
	public static ArrayList<String> findzip(String dong) {
		ArrayList<String> result = new ArrayList<String>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try{
			conn = OracleJDBC.openZipcode();
			ps = conn.prepareStatement(zipcodeSQL);
				ps.setString(1, "%" +dong + "%");
			rs = ps.executeQuery();
			
			while(rs.next()){
				StringBuilder sb = new StringBuilder();
				sb.append(rs.getString(1)).append(" ")
				.append(rs.getString(3)).append(" ")
				.append(rs.getString(4)).append(" ")
				.append(rs.getString(5)).append(" ")
				.append(rs.getString(6)).append(" ")
				.append(rs.getString(8)).append(" ")
				.append(rs.getString(9)).append(" ");
				result.add(sb.toString());
			}
				
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			OracleJDBC.closeConn(conn, ps, rs);
		}
		
		
		return result;
	}


	
	
}
